package spring.chatroom.java_chatroom.common.utils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

//这里储存的是没有发送出去的事件 userId表示
public class WaitToSendUtil {

    private static ConcurrentHashMap<Integer, List<Object>> eventMap = new ConcurrentHashMap<>();

    public static void setAttribute(Integer userId, Object session) {
        List<Object> list = eventMap.getOrDefault(userId, new ArrayList<>());
        list.add(session);
        eventMap.put(userId, list);
    }


    public static List<Object> getAttribute(Integer userId) {
        return eventMap.getOrDefault(userId,new ArrayList<>());
    }


    public static Object removeAttribute(Integer userId) {
        return eventMap.remove(userId);
    }

    public static Map<Integer, List<Object>> getSessionMap() {
        return eventMap;
    }
}
